import java.util.Random;
import java.util.Scanner;
public class 口算答题系统 {
    static Scanner scan = new Scanner(System.in);
    static Random random = new Random();//随机产生数
    static int ts;
    static int fw;
    static int ddts = 0, dcts;
    public static void main(String[] args) {
        System.out.println("欢迎进入口算答题系统");
        while (true) {
            System.out.println("请选择类型");
            System.out.println("1==加法" + "2==减法" + "3==乘法" + "4==除法" + "5==退出程序" + "6==混合运算" + "7==混合运算2.0" +"8==混合运算3.0");
            int n = scan.nextInt();
            switch (n) {
                case 1: {
                    System.out.println("请输入题数");
                    ts = scan.nextInt();
                    System.out.println("请输入数值范围");
                    fw = scan.nextInt();
                    jia(ts, fw);
                    break;
                }
                case 2: {
                    System.out.println("请输入题数");
                    ts = scan.nextInt();
                    System.out.println("请输入数值范围");
                    fw = scan.nextInt();
                    jian(ts, fw);
                    break;
                }
                case 3: {
                    System.out.println("请输入题数");
                    ts = scan.nextInt();
                    System.out.println("请输入数值范围");
                    fw = scan.nextInt();
                    cheng(ts, fw);
                    break;
                }
                case 4: {
                    System.out.println("请输入题数");
                    ts = scan.nextInt();
                    System.out.println("请输入数值范围");
                    fw = scan.nextInt();
                    chu(ts, fw);
                    break;
                }
                case 5: {
                    System.out.println("您已经退出程序");
                    System.exit(4);
                    break;
                }
                case 6: {
                    System.out.println("请输入题数");
                    ts = scan.nextInt();
                    System.out.println("请输入数值范围");
                    fw = scan.nextInt();
                    for (int i = 0; i < ts; i++) {
                        int n1 = random.nextInt(4) + 1;
                        if (n1 == 1) jia(1, fw);
                        if (n1 == 2) jian(1, fw);
                        if (n1 == 3) cheng(1, fw);
                        if (n1 == 4) chu(1, fw);
                    }
                }
                case 7: {
                            //(3+5)*                            System.out.println(n1 + "+" + n2 + "=");
                    System.out.println("请输入题数");
                    ts = scan.nextInt();
                    System.out.println("请输入数值范围");
                    fw = scan.nextInt();

                    for (int i = 0; i < ts; i++) {

                        int n1 = random.nextInt(4) + 1;
                        if (n1 == 1) jiahh(1, fw);
                        if (n1 == 2) jianhh(1, fw);
                        if (n1 == 3) chenghh(1, fw);
                        if (n1 == 4) chuhh(1, fw);


                    }


                }
            }
        }
}
    public static void jia ( int ts, int fw){
            for (int i = 0; i < ts; i++) {
                int n1 = random.nextInt(fw + 1);
                int n2 = random.nextInt(fw + 1);
                System.out.println(n1 + "+" + n2 + "=");
                System.out.println("请输入你的答案");
                int dn = scan.nextInt();//输入答案
                if (dn == n1 + n2) {
                    System.out.println("恭喜你答对了");
                    ddts++;
                } else {
                    System.out.println("你答错了");
                    dcts++;
                }
            }
        }

    //TODO------------------------------------------------------------->>>复合运算加法        jiahh
    public static void jiahh ( int ts, int fw){
        for (int i = 0; i < ts; i++) {
            int n1 = random.nextInt(fw + 1);
            int n2 = random.nextInt(fw + 1);
            System.out.println("(" + n1 + "+" + n2 + ")" + "+" + n2 + "=");
            System.out.println("请输入你的答案");
            int dn = scan.nextInt();//输入答案
            if (dn == (n1 + n2)+n2) {
                System.out.println("恭喜你答对了");
                ddts++;
            } else {
                System.out.println("你答错了");
                dcts++;
            }
        }
    }

    public static void jian ( int ts, int fw){
            for (int i = 0; i < ts; i++) {
                int n1 = random.nextInt(fw + 1);
                int n2 = random.nextInt(fw + 1);
                if (n1 < n2) {
                    int c;
                    c = n1;
                    n1 = n2;
                    n2 = c;
                }
                System.out.println(n1 + "-" + n2 + "=");
                System.out.println("请输入你的答案");
                int dn = scan.nextInt();
                if (dn == n1 - n2) {
                    System.out.println("恭喜你答对了");
                    ddts++;
                } else {
                    System.out.println("你答错了");
                    dcts++;
                }
            }
        }

    //TODO------------------------------------------------------------->>>复合运算减法        jianhh
    public static void jianhh ( int ts, int fw){
        for (int i = 0; i < ts; i++) {
            int n1 = random.nextInt(fw + 1);
            int n2 = random.nextInt(fw + 1);
            if (n1 < n2) {
                int c;
                c = n1;
                n1 = n2;
                n2 = c;
            }
            //System.out.println(n1 + "-" + n2 + "=");           // (9-5)*7+8/4
            System.out.println("(" + n1 + "-" + n2 + ")" + "*" + n2 + "+" +  n1 + "/" + n2 + "=");
            System.out.println("请输入你的答案");
            int dn = scan.nextInt();
            if (dn == ((n1 - n2)*n2 + n1/n2) ){
                System.out.println("恭喜你答对了");
                ddts++;
            } else {
                System.out.println("你答错了");
                dcts++;
            }
        }
    }

    public static void cheng ( int ts,int fw){
            for (int i = 0; i < ts; i++) {
                int n1 = random.nextInt(fw + 1);
                int n2 = random.nextInt(fw + 1);
                System.out.println(n1 + "*" + n2 + "=");
                System.out.println("请输入您的答案");
                int dn = scan.nextInt();//
                if (dn == n1 * n2) {
                    System.out.println("恭喜你答对了");
                    ddts++;
                } else {
                    System.out.println("你答错了");
                    dcts++;
                }
            }
        }

    //TODO------------------------------------------------------------->>>复合运算乘法        chenghh
    public static void chenghh ( int ts,int fw){
        for (int i = 0; i < ts; i++) {
            int n1 = random.nextInt(fw + 1);
            int n2 = random.nextInt(fw + 1);
            System.out.println("(" + n1 + "+" + n2 + ")" + "*" + n2 + "=");
            System.out.println("请输入您的答案");
            int dn = scan.nextInt();//
            if (dn == (n1+n2) * n2) {
                System.out.println("恭喜你答对了");
                ddts++;
            } else {
                System.out.println("你答错了");
                dcts++;
            }
        }
    }

    public static void chu ( int ts, int fw){
            for (int i = 0; i < ts; i++) {
                int n1 = random.nextInt(fw + 1);
                int n2 = random.nextInt(fw) + 5;
                int c;
               if (n1 != 0 && n1 < n2) {
                    c = n1;
                    n1 = n2;
                    n2 = c;
                }
                if (n1 % n2 == 0) {
                    System.out.println(n1 + "/" + n2 + "=");
                    System.out.println("请输入你的答案");
                    int dn = scan.nextInt();
                    if (dn == n1 / n2) {
                        System.out.println("恭喜你答对了");
                        ddts++;
                    } else {
                        System.out.println("你答错了");
                        dcts++;
                    }
                }
                else{
                        i--;   }
                }
            }

    //TODO------------------------------------------------------------->>>复合运算除法        chuhh
    public static void chuhh ( int ts, int fw){
        for (int i = 0; i < ts; i++) {
            int n1 = random.nextInt(fw + 1);
            int n2 = random.nextInt(fw) + 5;
            int c;
            if (n1 != 0 && n1 < n2) {
                c = n1;
                n1 = n2;
                n2 = c;
            }
            if (n1 % n2 == 0) {
                //System.out.println(n1 + "/" + n2 + "=");            //(9/2 + 3*5/9) / 3
                System.out.println("(" + n1 + "/" + n2 + "+" +  n1 + "*" + n2 + "/" + n2 + ")" + "/" + n1);
                System.out.println("请输入你的答案");
                int dn = scan.nextInt();
                if (dn == (n1/n2 + n1*n2/n2 ) / n1) {
                    System.out.println("恭喜你答对了");
                    ddts++;
                } else {
                    System.out.println("你答错了");
                    dcts++;
                }
            }
            else{
                i--;   }
        }
    }


}
